﻿// -----------------------------------------------------------------------
// <copyright file="NoResultTaskHelper.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Dhgms.TplHelper.Model.TaskHelper
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Dhgms.TplHelper.Model.Info;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class NoResultTaskHelper<TNoResultExecutorClass> : BaseTaskHelper<TaskResultBase>
        where TNoResultExecutorClass : NoResultExecutor.INoResultExecutor
    {
        protected NoResultTaskHelper(string name)
            : base(name)
        {
        }

        /// <summary>Entry point for doing the donkey work.</summary>
        /// <returns>The Execution Result.</returns>
        internal override TaskResultBase Execute()
        {
            this.Logger.Info("Starting Task: " + this.Name);
            var result = new TaskResultBase
            {
                Name = this.Name,
                Started = DateTime.Now,
            };

            var executor = this.GetExecutor();
            executor.Execute();

            result.Finished = DateTime.Now;
            this.Logger.Info("Finished Task: " + this.Name);
            return result;
        }

        protected abstract TNoResultExecutorClass GetExecutor();
    }
}
